package io.renren.dao;

import io.renren.common.dao.BaseDao;
import io.renren.dto.SmallCanteenPurchasemxDTO;
import io.renren.entity.SmallCanteenPurchasemxEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 小食堂采购明细表
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@Mapper
public interface SmallCanteenPurchasemxDao extends BaseDao<SmallCanteenPurchasemxEntity> {
    @Select("DELETE from canteens_small_canteen_purchasemx where small_canteen_purchase_id = " +
            "'${order}' ")
    void deleteOrder( Long order);

    //查询供应商
    @Select("SELECT * FROM canteens_small_canteen_purchasemx mx,canteens_supplier s WHERE mx.small_canteen_purchase_id ="+" '${id}' " +
            "AND mx.supplier_id=s.supplier_id GROUP BY mx.supplier_id")
    List<SmallCanteenPurchasemxDTO> seletGys(Long id);
    //查询供应商
    @Select("SELECT * FROM canteens_small_canteen_purchasemx mx WHERE mx.small_canteen_purchase_id ="+" '${id}' GROUP BY mx.supplier_id"
           )
    List<SmallCanteenPurchasemxDTO> seletGys2(Long id);
    //查询供应商下的材料信息

    @Select("SELECT (select B.box_id from canteens_small_canteen_purchase B where b.small_canteen_purchase_id = mx.small_canteen_purchase_id ) as box_id," +
            " mx.*, f.food_name,f.unit,A.create_date FROM canteens_small_canteen_purchasemx mx LEFT JOIN canteens_food f ON mx.food_id = f.food_id  " +
            " LEFT JOIN canteens_small_canteen_purchase A on a.small_canteen_purchase_id = mx.small_canteen_purchase_id " +
            "WHERE mx.small_canteen_purchase_id = '${id}'  AND mx.supplier_id = '${ids}'")
    List<SmallCanteenPurchasemxDTO> seletGysFood(long id,long ids);
    @Select("SELECT mx.* FROM canteens_small_canteen_purchasemx mx WHERE mx.small_canteen_purchase_id = '${id}' " +
            "AND mx.supplier_id = '${ids}' GROUP BY mx.small_canteen_purchase_id ")
    List<SmallCanteenPurchasemxDTO> seletGysFood1(long id,long ids);
    @Select("UPDATE canteens_small_canteen_purchasemx set sub_status = '${subStutas}' where small_canteen_purchasemx_id = '${id} '")
    void updateOrder1(long id,long subStutas);
    @Select("UPDATE canteens_small_canteen_purchasemx set purchase_num = '${purchaseNum}' where small_canteen_purchase_id =${orderId}  and food_id = ${foodId} ")
    void updateOrder2(long orderId,long foodId,float purchaseNum);
    @Select("DELETE from canteens_small_canteen_purchasemx where small_canteen_purchase_id =${orderId}  and food_id = ${foodId} ")
    void delectOrder(long orderId,long foodId);

    @Select("SELECT * FROM canteens_small_canteen_purchasemx where small_canteen_purchasemx_id  = " +"'${id}' ")
    SmallCanteenPurchasemxDTO gysMx(long id);

    //查询供应商下的材料信息
    @Select("SELECT m.create_date as create_date,mx.*,s.* FROM canteens_small_canteen_purchasemx mx,canteens_supplier s,canteens_small_canteen_purchase m WHERE mx.small_canteen_purchase_id ="+" '${id}'  " +
            " and m.small_canteen_purchase_id = mx.small_canteen_purchase_id AND mx.supplier_id=s.supplier_id and  mx.sub_status = 1   GROUP BY mx.supplier_id"
    )
    List<SmallCanteenPurchasemxDTO> gys1(Long id);
}